package com.ctshk.app.air.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.ChannelMainData;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.air.dto.app.*;
import com.ctshk.rpc.air.req.app.AirTicketsListReq;
import com.ctshk.rpc.air.req.app.MainDataRowFieldDataReq;
import com.ctshk.rpc.air.service.app.IAirProductAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.app.air.controller
 * @Author: hef
 * @CreateTime: 2021-04-16 09:55
 * @Description: 描述
 */
@Api(value = "APP机票产品", tags = "APP机票产品")
@RestController
@RequestMapping("/app-air-product")
public class AppAirProductController extends BaseController {

    @DubboReference
    private IAirProductAppService iAirProductAppService;

    @ApiOperation(value = "查询机票列表", notes = "查询机票列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询机票列表", operDesc = "查询机票列表")
    @PostMapping("/getTicketList")
    public Result<PageResponse<AirProductListDTO>> getTicketList(@RequestBody AirTicketsListReq req) {
        return iAirProductAppService.getTicketList(req);
    }

    /*@ApiOperation(value = "查询推荐机票", notes = "查询推荐机票")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询推荐机票", operDesc = "查询推荐机票")
    @GetMapping("/getRecommendedTicket")
    public Result<List<AirRecommendListDTO>> getRecommendedTicket() {
        return Result.success(iAirProductAppService.getRecommendedTicket());
    }*/

    @ApiOperation(value = "获取机票详情", notes = "获取机票详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "获取机票详情", operDesc = "获取机票详情")
    @GetMapping("/getProductDetail/{id}")
    public Result<AirProductDetailDTO> getProductDetail(@PathVariable(value = "id") Long id,
                                                        @RequestParam(value = "date", required = false) LocalDate date) {
        return Result.success(iAirProductAppService
                .getProductDetail(id, Optional.ofNullable(date).orElse(LocalDate.now()),ChannelMainData.APP_H5.getId()));
    }

    @ApiOperation(value = "获取多程机票详情", notes = "获取多程机票详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "获取多程机票详情", operDesc = "获取多程机票详情")
    @GetMapping("/getMultipassProductDetail/{id}")
    public Result<List<AirProductDetailDTO>> getMultipassProductDetail(@PathVariable(value = "id") String id,
                                                        @RequestParam(value = "date", required = false) LocalDate date) {
        return Result.success(iAirProductAppService
                .getMultipassProductDetail(id, Optional.ofNullable(date).orElse(LocalDate.now()),ChannelMainData.APP_H5.getId()));
    }

    @GetMapping("/getHomePageData")
    @ApiOperation(value = "获取机票首页数据", notes = "获取机票首页数据")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "获取机票首页数据", operDesc = "获取机票首页数据")
    public Result<HomePageDataDto> getHomePageData(){
        return Result.success(iAirProductAppService.getHomePageData());
    }

    @PostMapping("/query/fieldLike/name")
    @ApiOperation(value = "航空公司和仓位等级", notes = "根据行id和字段id查询值,去重主数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "根据行id和字段id查询值和名称模糊", operDesc = "内部接口，根据行id和字段id查询值")
    public Result<List<MainDataRowFieldDataDTO>> queryFieldLikeName(@RequestBody @Valid MainDataRowFieldDataReq req) {
        return Result.success(iAirProductAppService.queryFieldLikeName(req));
    }

    @PostMapping("/getMonthFloorPrice")
    @ApiOperation(value = "获取一个月内的最低价格", notes = "获取一个月内的最低价格")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET,
            operType = OperationLogType.QUERY, operTitle = "获取一个月内的最低价格", operDesc = "获取一个月内的最低价格")
    public Result<List<CalendarLowestPriceDTO>> getMonthFloorPrice(@RequestBody AirTicketsListReq req) {
        //增加修改返回集合对象
        return Result.success(iAirProductAppService.getMonthFloorPrice(req.setChannelId(ChannelMainData.APP_H5.getId())));
    }

}
